﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLL.BusinessRules
{
    public class ValidateRequired:BusinessRule
    {
        public ValidateRequired(string propertyName)
            : base(propertyName)
        {
            ErrorMessage = string.Format("{0} is a required field.", propertyName);
        }

        public ValidateRequired(string propertyName, string errorMessage)
            : this(propertyName)
        {
            ErrorMessage = errorMessage;
        }

        public override bool Validate(BusinessObject businessObject)
        {
            try
            {
                return (GetPropertyValue(businessObject).ToString().Length > 0);
            }
            catch { return false; }
        }
    }
}
